/*
 * Copyright © 2004-2014 chenYuan. All rights reserved.
 * @Website:wwww.jspx.net
 * @Mail:39793751@qq.com
 * @author: chenYuan , 陈原
 * @License: Jspx.net Framework Code is open source (LGPL)，Jspx.net Framework 使用LGPL 开源授权协议发布。
 * @jvm:jdk1.6+  x86/amd64
 *
 */
package com.jspx.sioc.aop;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.jspx.utils.FileUtil;
import com.jspx.utils.StringUtil;
import java.io.File;

/**
 * Created with IntelliJ IDEA.
 * User: chenyuan
 * Date: 12-10-28
 * Time: 下午5:24
 *
 */
public class DeleteFileAopBean extends AbstractAopBean
{
    final private static Logger log = LoggerFactory.getLogger(ShellAopBean.class.getName());
    private String folder = StringUtil.empty;
    private int day = 60;
    private  String types;
    private int need = 1;
    private boolean enable = true;


    public String getFolder() {
        return folder;
    }

    public void setFolder(String folder) {
        this.folder = folder;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public String getTypes() {
        return types;
    }

    public void setTypes(String types) {
        this.types = types;
    }

    public int getNeed() {
        return need;
    }

    public void setNeed(int need) {
        this.need = need;
    }

    public boolean isEnable()
    {
        return enable;
    }

    public void setEnable(boolean enable)
    {
        this.enable = enable;
    }

    public java.lang.String init() throws java.lang.Exception
    {
        if (enable && !StringUtil.isNULL(folder))
            try
            {
                File file = new File(folder);
                if (file.isDirectory()&&file.exists())
                    FileUtil.deleteFile(file,day,types,need);
            } catch (Exception e)
            {
                log.error(folder,e);
                e.printStackTrace();
            }
        return SUCCESS;
    }

    public java.lang.String destroy() throws java.lang.Exception
    {
        return SUCCESS;
    }
}